package cn.walls1717.wallsmall.cart.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池配置
 *
 * @author walls1717
 * @since 2022/11/11 14:18
 **/
@Configuration
public class ThreadConfig {
    @Resource
    private ThreadPoolPropertiesConfig pool;

    @Bean
    public ThreadPoolExecutor executor() {
        return new ThreadPoolExecutor(pool.getCoreSize(), pool.getMaxSize(), pool.getKeepAliveTime(), TimeUnit.SECONDS, new LinkedBlockingDeque<>(100000),
            Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
    }
}
